﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using CID.Domain.Development;
using CID.Domain.Operations;
using CID.Execution.Support.Information;

namespace CID.Execution.Support.Scripting
{
    [DataContract]
    public class ActivationScriptStep : ScriptStep
    {
        internal ActivationScriptStep() : base() { }

        //TODO: remove
        public ActivationScriptStep(IComponent component, IEnvironment targetEnvironment) :
            base(component.ActivationDeactivationDefinition.ActivationTemplate, component.ActivationDeactivationDefinition.GetActivationParamaterValues(targetEnvironment))
        {
            Component = new ComponentInfo(component);
        }

        public ActivationScriptStep(IComponent component, IEnvironment targetEnvironment, IEnumerable<IServer> targetServers) :
            base(component.ActivationDeactivationDefinition.ActivationTemplate, component.ActivationDeactivationDefinition.GetActivationParamaterValues(targetEnvironment), targetServers)
        {
            Component = new ComponentInfo(component);
        }

        [DataMember]
        public ComponentInfo Component { get; set; }

        public ActivationScriptStep Clone()
        {
            return new ActivationScriptStep() { Template = Template.Clone(), Component = Component.Clone(), ParameterValues = ParameterValues.Select(x => x.Clone()).ToArray() };
        }
    }
}
